from typing import Union
from fastapi import APIRouter, Depends, Query
from src.base.beans import Rest, PageParam
from src.config.auth import auth_depend
from src.config.log import log_depend
from src.dao.sys_user_dao import get_user_by_id, get_user_list_by_condition, get_user_page_by_condition
from src.domain.sys_user import SysUser, SysUserReq

router = APIRouter(prefix='/user', dependencies=[Depends(auth_depend), Depends(log_depend)], tags=["用户管理"])


@router.get("/list", summary="根据条件查询用户列表", )
async def get_user_list(search: SysUser = Query(default=None)):
    users = get_user_list_by_condition(search)
    return Rest.ok(users)


@router.get("/page", summary="根据条件分页查询用户列表", )
async def get_user_page(search: SysUserReq = Query(default=None)):
    users = get_user_page_by_condition(search)
    return Rest.ok(users)


@router.get("/{user_id}", summary="根据ID 获取用户信息", )
async def get_user_by_id(user_id: int):
    sys_user = get_user_by_id(user_id)
    return Rest.ok(sys_user)
